package core.util;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

public class Page<T> {
	private int count;// 总记录数
	private int pageCount;// 总页数
	private int pageSize = 10;// 页面大小
	private int pageNo;// 当前页面
	private List<T> list;
	
	public Page() {
		this.pageNo = 1;
	}
	public Page(int pageNo) {
		this.pageNo = pageNo;
	}
	
	public Page(int pageNo,int pageSize) {
		this.pageSize = pageSize;
		this.pageNo = pageNo;
	}
	
	public Page(HttpServletRequest request) {
		this.pageNo = WebUtil.getInt(request, 1, "pageNo");
		this.pageSize = WebUtil.getInt(request, this.pageSize, "pageSize");
	}
	
	public Page(int count, int pageSize, int pageNo, List<T> list) {
		this.count = count;
		this.pageSize = pageSize;
		this.pageNo = pageNo;
		this.list = list;
		this.pageCount = getPageCount(count, pageSize);
	}

	public int getPageCount(int count, int pageSize) {
		if (pageSize == 0) {
			pageSize = 1;
		}
		int pg = (count + pageSize - 1) / pageSize;
		return pg;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
		this.pageCount = getPageCount(count, pageSize);
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public List<T> getList() {
		return list;
	}

	public void setList(List<T> list) {
		this.list = list;
	}
	
	public Page<T> returnPage(List<T> list) {
		this.list=list;
		return this;
	}
}
